package Offer;

public class Test04 
{

	public static void main(String[] args) 
	{
		char[]ch={'w','e',' ','a','r','e',' ','h','a','p','p','y'};
		char[] ch1 = {'a',' ','c',' ','d'};
		//System.out.println(replaceSpace(ch));
		System.out.println(replaceSpace(ch));

	}
	public static String replaceBlank(char[]ch) 
	{
		int num = 0;
		for(int i=0;i<ch.length;i++){
			if(ch[i]==' '){
				num+=2;
			}
			num++;
		}
		char[] chr = new char[num];
		int j=0;
		int k=0;
		while(j<=ch.length-1)
		{
			if(ch[j] ==' ')
			{
				chr[k++]='%';
				chr[k++]='2';
				chr[k++]='0';
			}else
			{
				chr[k]=ch[j];
				k++;
			}
			j++;
		}
		return new String(chr);
	}
	public static String replaceSpace(char [] ch){
		int num = 0;
		int length = ch.length;
		for(int i = 0; i < length; i++){
			if(ch[i] == ' '){
				num ++;
			}
		}
		char []newCh = new char[length + num * 2];
		for (int i = 0,k = 0; i < length; i++) {
			if(ch[i] == ' '){
				newCh[k++] = '%';
				newCh[k++] = '2';
				newCh[k++] = '0';
			}else{
				newCh[k++] = ch[i];
			}
		}
		
		return String.valueOf(newCh);
	}
}
